//
//  PlayerInfoLayer.cpp
//  DiceWar
//
//  Created by xiaofeng on 27/6/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include "PlayerInfoLayer.h"
#include "GameConstants.h"

namespace  
{
    const char* kRedCellSpritePath = "red.png";
    const char* kGrayCellSpritePath = "gray.png";
    const char* kBlueCellSpritePath = "blue.png";
    const char* kOrangeCellSpritePath = "orange.png";
    const char* kBlackCellSpritePath = "black.png";
}

bool PlayerInfoLayer::init()
{
    m_pCurrentPlayerSprite = NULL;
    return true;
}

void PlayerInfoLayer::setCurrentPlayer(PlayerType player)
{
    if (m_pCurrentPlayerSprite) this->removeChild(m_pCurrentPlayerSprite, true);
    
    const char* currentPlayerSpritePath = getPlayerSpritePath(player);
    m_pCurrentPlayerSprite = cocos2d::CCSprite::spriteWithFile(currentPlayerSpritePath);
    
    const cocos2d::CCSize kSize = m_pCurrentPlayerSprite->getContentSize();
    const int kTextureWidth = kSize.width;
    const float kScale = static_cast<float>(gameConstants::kHexGridSize * 2) / static_cast<float>(kTextureWidth);
    m_pCurrentPlayerSprite->setScale(kScale);
    m_pCurrentPlayerSprite->setPosition(ccp(cocos2d::CCDirector::sharedDirector()->getWinSize().width - 20, 80));
    
    this->addChild(m_pCurrentPlayerSprite);
}

const char* PlayerInfoLayer::getPlayerSpritePath(PlayerType player)
{
    switch (player) 
    {
        case kRedPlayer: return kRedCellSpritePath;
        case kBluePlayer: return kBlueCellSpritePath;
        case kBlackPlayer: return kBlackCellSpritePath;
        case kOrangePlayer: return kOrangeCellSpritePath;
        case kInvalidPlayer: return kGrayCellSpritePath;
        default: break;
    }
    
    return kGrayCellSpritePath;
}